package com.dance.spring.learn.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class UserProxy {

    @Pointcut(value = "execution(* com.dance.spring.learn.aop.User.add(..))")
    public void pointcut(){}

    /**
     * 前置通知
     */
    @Before(value = "pointcut()")
    public void before() {
        System.out.println("before......");
    }

    /**
     * 后置通知（返回通知）
     */
    @AfterReturning(value = "pointcut()")
    public void afterReturning() {
        System.out.println("afterReturning.........");
    }

    /**
     * 最终通知
     */
    @After(value = "pointcut()")
    public void after() {
        System.out.println("after.........");
    }

    /**
     * 异常通知
     */
    @AfterThrowing(value = "pointcut()")
    public void afterThrowing() {
        System.out.println("afterThrowing.........");
    }

    /**
     * 环绕通知
     * @param proceedingJoinPoint
     * @return
     * @throws Throwable
     */
    @Around(value = "pointcut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前.........");
        //被增强的方法执行
        Object proceed = proceedingJoinPoint.proceed();
        System.out.println("环绕之后.........");
        return proceed;
    }


}
